package vn.team.clipxonxao.respone;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import vn.team.clipxonxao.model.VideoClip;
import vn.team.clipxonxao.model.VideoClipList;
import vn.team.clipxonxao.utils.ConfigApp;
import android.util.Log;

import com.mk.fw.connection.APIDataResponse;
import com.mk.fw.connection.APIResponse;

public class DetailPageRespone extends APIResponse{

	
	private VideoClipList listVideo;
	private List<VideoClip> list;
	
	
	public DetailPageRespone(APIDataResponse dataResponse) {
		super(dataResponse);
	}

	@Override
	public void parseResponse(APIDataResponse response) {
		
		if (response == null) {
			return;
		}
		Log.e("DetailPageRespone", "Data response=" + response.getData());
		try {
			if(response.getData()!=null && response.getData().compareTo("")!=0){
				JSONObject jsonObject = new JSONObject(response.getData());
				int code = jsonObject.getInt(ConfigApp.CODE);
				if (code == APIResponse.SERVER_SUCCESS) {
					listVideo = new VideoClipList();
					list = new ArrayList<VideoClip>();
					if(!jsonObject.isNull(ConfigApp.DATA)){
						JSONArray jsonObject2 = jsonObject.getJSONArray(ConfigApp.DATA);
						for (int i = 0; i < jsonObject2.length(); i++) {
							JSONObject object = jsonObject2.getJSONObject(i);
							String id = object.getString(ConfigApp.ID);
							String title = object.getString(ConfigApp.TITLE);
							String img = object.getString(ConfigApp.IMG);
							String description = object.getString(ConfigApp.DESCRIPTION);
							String time = object.getString(ConfigApp.TIME);
							VideoClip clipVideo = new VideoClip(id, title, img, description, time);
							list.add(clipVideo);
						}
						listVideo.setListCategory(list);
					}else{
						return;
					}
				}else{
					return;
				}
			}else{
				return;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			setCode(APIResponse.CLIENT_ERROR_PARSE_DATA);
		}
	}
	
	public VideoClipList getListCategory(){
		return listVideo;
	}

}
